package framework.ui;

import org.openems.entity.Key;

import framework.DomainService;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;

public class EmsButton extends Pane {
	public Button getButton() {
		return button;
	}

	private Button button;
	
	public EmsButton(Button button, Key key, DomainService service) {
		this.button = button;
		initialize(key, service);
	}
	
	public EmsButton(Key key, DomainService service) {
		this.button = new Button();
		this.getChildren().add(button);
		initialize(key, service);
	}

	private void initialize(Key key, DomainService service) {
		new EmsButtonConnector(new IButton() {

			@Override
			public void setText(String nextText) {
				button.setText(nextText);
			}

			@Override
			public void setOnAction(final IButtonListener listener) {
				button.setOnAction(new EventHandler<ActionEvent>() {
					@Override
					public void handle(ActionEvent arg0) {
						listener.onClick();
					}
				});
			}

			@Override
			public String getText() {
				return button.getText();
			}
			
		}, service, key);
	}

}
